<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>无标题文档</title>
    <link href="../../style/css/style.css" rel="stylesheet" type="text/css"/>
    <script src="../../style/js/jquery-1.8.3.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function (){
            findAdList();
        })

        //查询所有部门信息
        function findAdList(){
            $.get("../../ad/list",function (res){
                if(res==500){
                    alert("服务器繁忙,请稍后再试");
                }else {
                    console.log(res);
                    var str = "";
                    for (var i = 0; i < res.data.length; i++) {
                        var  imgsrc ="http://127.0.0.1:8888/userImg/ad/"+res.data[i].imgSrc;
                        str += "<tr align='center'>";
                        str += "<td>"+(i+1)+"</td>";
                        str += "<td>"+res.data[i].adPosition+"</td>";
                        if(res.data[i].imgSrc==null||res.data[i].imgSrc==undefined){
                            str += "<td>未上传广告图</td>";
                        }else{
                            str += "<td><img src='"+imgsrc+"' width='50px' height='50px'></td>";
                        }
                        str += "<td>"+res.data[i].url+"</td>";
                        str += "<td>&nbsp;&nbsp;&nbsp;&nbsp;<a href='javaScript:void(0)' style='color: #646c91' onclick='todelete("+res.data[i].id+")'>删除</a></td>";
                        str += "</tr>";
                    }
                    $("#tableId").append(str);
                }
            },"json")
        }

        function toupdate(id){
            location.replace("update.html?id="+id);
        }


        function todelete(did){
            if(confirm("确定删除这项吗?"+did)){
                $.post("../../ad/delete",{id:did},function (res){
                    if(res.code==200){
                        alert("删除成功");
                        location.replace("list.html");
                        return;
                    }else{
                        alert("服务器繁忙....");
                        return;
                    }
                })
            }
        }

    </script>




</head>


<body>
<div class="rightinfo">
    <!-- 顶部按钮 -->
    <div class="tools">
        <ul class="toolbar">
            <a href="add.html">
                <li class="click">
                    <span><img src="../../style/img/adminMainPicture/t01.png" /></span>
                    添加
                </li>
            </a>
        </ul>
    </div>
    <!--数据列表 -->
    <form >
        <table class="tablelist" id="tableId">
            <th>编号<i class="sort"><img src="../../style/img/adminMainPicture/px.gif" /></i></th>
            <th>广告位</th>
            <th>广告图</th>
            <th>链接地址</th>
            <th>操作事项</th>
        </table>
    </form>
</div>
</body>
</html>
